import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class MovieService {

    private static List<Movie> movies = new ArrayList<>();
    private static Scanner sc = new Scanner(System.in);
    public void start() {
        while (true) {
            System.out.println("=============电影推荐系统=============");
            System.out.println("1,上架");
            System.out.println("2,下架");
            System.out.println("3,查询");
            System.out.println("4,封杀");
            System.out.println("5,退出");
            System.out.print("请选择：");

            String command= sc.next();
            switch (command) {
                case "1":
                    // 上架
                    addMovie();
                    break;


                case "2":
                    // 下架

                    break;

                case "3":
                    // 查询
                    queryMovie();
                    break;

                case "4":
                    // 封杀
                    deleteStar();
                    break;

                case "5":
                    // 退出
                    System.exit(0);
                    break;

                default:
                    System.out.println("输入错误，请重新输入！");
                    break;


            }
        }

    }

    private void deleteStar() {
        Movie movie = new Movie();
        System.out.print("请输入要封杀的电影名称：");
        String start = sc.next();
        for(int i = 0;i<movies.size();i++){
            if(movie.getActor().contains(start)){
                movies.remove(movie);
                i--;
            }
        }
    }

    /**
     * 查询电影
     */
    private void queryMovie() {
        System.out.println("请输入要查询的电影名称：");
        String name = sc.next();
        Movie movie = queryMovieByName(name);
        if (movie == null) {
            System.out.println("没有找到该电影！");
        } else {
            System.out.println("电影" + movie);
        }




    }
    public Movie queryMovieByName(String name){
        for (Movie movie : movies) {
            if (movie.getName().equals(name)) {
                return movie;
            }
        }
        return null;
    }


    /**
     * 添加电影
     */
    private void addMovie() {
        Movie movie = new Movie();
        System.out.print("请输入电影名称：");
        movie.setName(sc.next());
        System.out.print("请输入电影演员：");
        movie.setActor(sc.next());
        System.out.print("请输入电影价格：");
        movie.setPrice(sc.nextDouble());
        System.out.print("请输入电影评分：");
        movie.setScore(sc.nextDouble());
        movies.add(movie);





        System.out.println("上架成功");

    }
}
